package library;

import java.util.Vector;

import javax.swing.table.DefaultTableModel;

public class BookModel extends DefaultTableModel
{
	private static final long serialVersionUID = 4938406157773860469L;
	
	public BookModel(Vector<Book> v)
	{
		super.setColumnIdentifiers(new String[]{"ID", "ISBN", "Titel", "Autor", "Zustand"});
		
		for (int i = 0; i < v.size(); ++i)
		{
			super.addRow(new String[]
					{
						Integer.toString(v.elementAt(i).getId()),
						v.elementAt(i).getIsbn(),
						v.elementAt(i).getTitle(),
						v.elementAt(i).getAuthor(),
						v.elementAt(i).getState().toString()
					});
		}
	}
	
	public void add(Book b)
	{
		super.addRow(new String[]
				{
					Integer.toString(b.getId()),
					b.getIsbn(),
					b.getTitle(),
					b.getAuthor(),
					b.getState().toString()
				});
	}
	
	public void reBuild(Vector<Book> v)
	{
		super.setNumRows(0);
		
		for (int i = 0; i < v.size(); ++i)
		{
			super.addRow(new String[]
					{
						Integer.toString(v.elementAt(i).getId()),
						v.elementAt(i).getIsbn(),
						v.elementAt(i).getTitle(),
						v.elementAt(i).getAuthor(),
						v.elementAt(i).getState().toString()
					});
		}
	}

	@Override
	public boolean isCellEditable(int row, int column)
	{
		return false;
	}
	
	
}
